<style type="text/css">
    .selected-search {
        box-shadow: 0 1px 6px rgba(0,0,0,.2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <Form-item label="车辆" prop="personalName">
            <p @click="selectStationIsShow ? selectStationIsShow =false : selectStationIsShow = true" class="select-click">
                {{checkerName}}</p>
            <div v-if="selectStationIsShow" class="selected-search">
                <div class="search-action" style="display: flex">
                    <i-input v-model="keyword" placeholder="输入签退车辆车牌号"></i-input>
                    <i-button @click="getSearchData()" type="ghost" shape="circle" icon="ios-search"
                              style="margin-left: 10px"></i-button>
                </div>
                <div class="selected-arr">
                    <template v-if="checkerArr.length > 0">
                        <template v-for="(item,index) in checkerArr">
                            <p @click="chooseStation(item.id,item.address)" class="selected-item">{{item.address}}</p>
                        </template>
                    </template>
                    <template v-else>
                        <p class="selected-item">暂无数据</p>
                    </template>

                </div>
            </div>
        </Form-item>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">签退</i-button>
            <i-button type="ghost" style="margin-left: 8px">取消</i-button>
        </Form-item>
    </i-form>

</template>
<script>
    import apiUtil from '../../assets/utils/api_util';

    export default {
        data() {
            return {
                visitorid:'',
                formValidate: {
                    //添加字段
                    carcode: '',
                },
                ruleValidate: {
                    carcode: [
                        {required: true, message: '车牌号', trigger: 'blur'}
                    ],
                },
                upLoadFile: apiUtil.urls.UploadFile,
                apiUtilBase: apiUtil.urls.baseUrl,
                //值班岗位选择操作
                checkerId: '',
                checkerArr: [],
                checkerName: '请选择签退车辆',
                selectStationIsShow: false,
                keyword:'',
            }
        },
        mounted: function () {
            let id = this.$route.query.id;

            if (id && id.length > 0) {

                this.getDetail(id)
            }

        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                this.$refs[name].validate((valid) => {
                    that.updateData(model);
                })
            },

            //岗位列表
            getSearchData() {
                let that = this;

                let para = {
                    keyword: this.keyword,
                };

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.SearchVistirorCar, para, function (res) {
                    that.$Loading.finish();
                    that.checkerArr = res.Msg;
                });
            },
            chooseStation: function (id, name) {
                this.checkerId = id;
                this.checkerName = name;
                this.selectStationIsShow = false;

            },

            //修改
            updateData: function (model) {
                let that = this;

                model.id = this.$route.query.id;
                model.visitorid = this.visitorid;
                model.state = '退卡';

                let params = that.$qs.stringify(model);

                this.$Loading.start();

                apiUtil.post(that,apiUtil.urls.EditVisitorCar, params, function (res) {
                    that.$Loading.finish();
                    that.$message.success('签退成功')
                });
            },


        }
    }
</script>
